<template>
	<view class="container">
		<view class="top-bg">
			<up-navbar @leftClick="back" :fixed="false" leftIconColor="#fff" bgColor="transparent">
				<template #center>
					<view style="color:#fff;">账户余额</view>
				</template>
			</up-navbar>
			<view class="balance-money">
				<up-count-to :startVal="0" :endVal="2500" fontSize="36" color="#fff"></up-count-to>
			</view>
		</view>
		<view class="listbox">
			<up-collapse value="1" accordion :border="false">
				<up-collapse-item name="1">
					<template #title>
						<view class="slot-title">
							<img class="img" src="@/static/balance.png" alt="" />
							<view>余额明细</view>
							<view style="margin-left: 20rpx;display: flex;align-items: baseline;" @click.stop="optime()">{{time}}&nbsp;<up-icon name="arrow-down-fill" size="24rpx"></up-icon></view>
							
						</view>
					</template>
					<view class="u-collapse-content" v-for="(item,index) in list">
						<view class="top">	
							<view class="name">
								平台充值
							</view>
							<view class="price">
								+{{item.withdraw_amount}}
							</view>
						</view>
						<view class="bottom">
							{{item.arrival_time}}
						</view>
					</view>
					<up-divider></up-divider>
				</up-collapse-item>
			</up-collapse>
		</view>
		<up-datetime-picker :show="show" v-model="value1" mode="year-month" @confirm="sure" @cancel="show = false"></up-datetime-picker>
	</view>
</template>

<script>
	import {
		http
	} from 'uview-plus'
	export default {
		data() {
			return {
				show: false,
				time: dateFormatter(Date.now()),
				datetimePickerRef :null
			}
		},
		onLoad(){
			this.getlist()
		},
		methods: {
			async getlist(){
				await http.get('/shop/user/withdraw',{params:{status:2,filter_time:this.time}}).then(res=>{
					this.list=res.items
				})
			},
			back(){
				uni.navigateBack({
					delta: 2
				})
			},
			optime() {
				this.show = true
			},
			sure(e){
				console.log(e);
				var d = new Date(e.value);
				var year = d.getFullYear();
				var month = (d.getMonth()+1)<10 ? '0'+(d.getMonth()+1) : (d.getMonth()+1);
				this.time =  [year, month].join('-');  
				this.getlist()
				this.show = false
			}
			
		},
	}
	const dateFormatter =(str)=>{//默认返回yyyy-MM-dd HH-mm-ss
	    var d = new Date(str);
	    var year = d.getFullYear();
	    var month = (d.getMonth()+1)<10 ? '0'+(d.getMonth()+1) : (d.getMonth()+1);
	    return [year, month].join('-');  
		console.log(str)
	}
</script>

<style lang="scss">
	page {
		height: 100%;

		.container {
			height: 100%;
		}
	}

	.top-bg {
		width: 100%;
		height: 40%;
		overflow: hidden;
		background: #0B9EE2;

	}

	.balance-money {
		font-family: 思源黑体;
		font-size: 72rpx;
		font-weight: normal;
		line-height: 40rpx;
		text-align: center;
		letter-spacing: 4rpx;
		margin-top: 20%;
		color: #FFFFFF;
	}

	.listbox {
		width: 690rpx;
		border-radius: 20rpx;
		background: #fff;
		margin: 20rpx auto;
		overflow: hidden;

		.slot-title {
			display: flex;
			align-items: center;
			.img {
				width: 60rpx;
				height: 60rpx;
				margin-right: 10rpx;
			}
		}
	}
	.u-collapse-content{
	}
	.top{
		display: flex;
		justify-content: space-between;
		font-size: 26rpx;
		font-weight: normal;
		text-align: justify; /* 浏览器可能不支持 */
		letter-spacing: 0px;	
		color: #24292E;
	}
	.bottom{
		font-size: 24rpx;
		color: #999999;
		margin-top: 14rpx;
	}
</style>